package com.starling.extend.touch
{
	import starling.display.DisplayObject;
	import starling.display.DisplayObjectContainer;
	
	public class TouchObjectManage
	{
		public static const MOVIE:String = "Movie";
		public static const COLOR:String = "Color";
		public static const ALPHA:String = "Alpha";
		
		private static const displays:Vector.<TouchObject> = new Vector.<TouchObject>();
		
		/**
		 * 注册Touch对象 
		 * @param target 目标对象
		 * @param callback 返回函数
		 * @param downStyle 按下样式 color为色块 frame为跳帧(target 类型必须为FrameMovie)
		 * 
		 */		
		public static function register(target:DisplayObject ,callback:Function ,downStyle:String=null):void
		{
			unregister(target ,callback);
			var touchObj:TouchObject = new TouchObject(target ,callback ,downStyle);
			displays.push(touchObj);
		}
		
		/**
		 * 注销Touch对象 
		 * @param target
		 * 
		 */		
		public static function unregister(target:DisplayObject ,callback:Function):void
		{
			var i:int=0;
			var length:int = displays.length;
			for (i;i<length;i++)
			{
				if(displays[i].target == target && displays[i].callback == callback)
				{
					var touchObject:TouchObject = displays.splice(i ,1)[0];
					touchObject.dispose();
					touchObject = null;
					return;
				}
			}
		}
	}
}